package com.hyf.webdemo;

import org.springframework.boot.SpringApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
public class BookApplication {


    @RequestMapping(value = "/available")
    public String available(){
        System.out.println("Spring n Action");
        return "Spring in Action";
    }

    @RequestMapping(value = "/forward")
    public void forward(HttpServletRequest request, HttpServletResponse response){
        try {
            request.getRequestDispatcher("/forwardSucess").forward(request,response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping(value = "/forwardSucess")
    public String forwardSucess(){
        return "forwardSucess";
    }
    @RequestMapping(value = "/redirect")
    public void redirect(HttpServletRequest request, HttpServletResponse response){
        try {
            response.sendRedirect("/redirectSuccess");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RequestMapping(value = "/redirectSuccess")
    public String redirectSuccess(){
        return "redirectSuccess";
    }


    public static void main(String[] args){
        SpringApplication.run(BookApplication.class,args);
    }
}
